package com.px.base.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.px.common.core.domain.AjaxResult;
import com.px.base.domain.RiverBasin;
import com.px.base.domain.RiverSystem;
import com.px.base.mapper.FactorMapper;
import com.px.base.mapper.RiverBasinMapper;
import com.px.base.mapper.RiverSystemMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 基础数据 Controller，用于放一下Base模块中单个的接口，少建一些Controller
 *
 * @author 品讯科技
 * @date 2024-08
 */
@Api(value = "基础数据 控制器", tags = {"基础数据"})
@RestController
@RequestMapping("/base")
@AllArgsConstructor
public class BaseIndexController {

    private final RiverBasinMapper riverBasinMapper;
    private final RiverSystemMapper riverSystemMapper;
    private final FactorMapper factorMapper;

    @ApiOperation("查询服务器时间")
    @GetMapping("/getTime")
    public AjaxResult getTime() {
        Map<String, Object> data = new HashMap<>(4);
        data.put("dbTime", factorMapper.queryNowTime());
        data.put("serverTime", LocalDateTime.now());
        return AjaxResult.success(data);
    }

    /**
     * 查询水环境监测因子列表
     */
    @ApiOperation(value = "查询水环境监测因子列表", notes = "name:因子名称，manual:传1查地表水手工监测因子")
    @GetMapping("/factorList")
    public AjaxResult<List> list(String name, Integer manual) {
        return AjaxResult.success(factorMapper.queryList(name, manual));
    }

    /**
     * 查询流域列表
     */
    @ApiOperation("查询流域列表")
    @GetMapping("/riverBasinList")
    public AjaxResult<List> riverBasinList(String name) {
        return AjaxResult.success(riverBasinMapper.selectList(Wrappers.lambdaQuery(RiverBasin.class).eq(StrUtil.isNotBlank(name), RiverBasin::getName, name)));
    }

    /**
     * 查询水系列表
     */
    @ApiOperation("查询水系列表")
    @GetMapping("/riverSystemList")
    public AjaxResult<List> riverSystemList(String name) {
        return AjaxResult.success(riverSystemMapper.selectList(Wrappers.lambdaQuery(RiverSystem.class).eq(StrUtil.isNotBlank(name), RiverSystem::getName, name)));
    }

}
